using System;
using Cysharp.Threading.Tasks;
using Framework.Extension.UI.LoopList;
using Framework.Helper;
using Game.Model.ServerList;
using UnityEngine;
using UnityEngine.UI;

namespace Game.Logic.Auth.ServerList.Items
{
    public class ServerListItemView : LoopListItem
    {
        public Button btnCheck;
        public Text txtServerName;
        public Text txtState;
        
        private ServerInfoDto serverDto;

        private void Start()
        {
            btnCheck.AddListener(OnSelect);
        }

        public override void SetData(object data)
        {
            serverDto = data as ServerInfoDto;

            UpdateUI();
        }

        private void UpdateUI()
        {
            txtServerName.text = serverDto.name;
            txtState.text = "推荐";
        }

        private async UniTask OnSelect()
        {
            Debug.Log("---===  " + serverDto.name);
            await UniTask.CompletedTask;
        }
    }
}